﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,minimum-scale=1.0, user-scalable=no" />
<link rel="shortcut icon" href="/Images/ico/favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="/css/swiper.min.css" />
<link rel="stylesheet" type="text/css" href="/css/style.css" />
<link type="text/css" rel="stylesheet" href="/layui/css/layui.css"  media="all">
<script type="text/javascript" src="/layui/layui.js" charset="utf-8"></script>
<script src="/js/jquery.min.js" type="text/javascript"></script>
<script src="/js/swiper.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/js/layui-post.js"></script>
</head>
<body style="background: #f3f0f0;">
    <div class="ng-scope">
        <div class="loca ng-scope title-order" style="background: #f9fafd;">
            <a class="title-top" href="javascript:window.history.back();"></a>
            <a class="title-center">订单管理</a>
            <a class="title-right" href="/index"></a>
        </div>
        <ul class="navlist" style="height: 35px;margin-top: 50px;position: fixed;width: 100%;top: 0px;z-index: 10;background: #FFFFFF;border-bottom: 1px dotted #ccc;">
            <li type="tof" data-field="isSure" data-value="0" status="1" order-status="ORDER_STATUS_20" class="active">待确认</li>
            <li type="tof" data-field="status" data-value="0">待支付</li>
            <li type="tof" data-field="orderStatus" data-value="ORDER_STATUS_22<->ORDER_STATUS_23">待收货</li>
            <li type="tof" data-field="orderStatus" data-value="ORDER_STATUS_24">待评价</li>
        </ul>
        <div class="orderlist" id="order_lists" style="margin-top: 85px;">
            <div style="height: 8px;"></div>
            <!--购物车空提示-->
            <div class="cartempty ng-scope ng-hide">
                <h3>暂无订单</h3>
            </div>
            <!--/购物车空提示-->
            <ul class="lists ng-scope" style="margin: 0 auto;width: 96%;" id="orders"></ul>
        </div>
    </div>
</body>
<script>
$.ajaxSetup({contentType: "application/json; charset=utf-8"});
var userInfo = $.parseJSON(sessionStorage.getItem("userInfo")),enumsData=[];
layui.use(['layer','form','element','util'], function(){
    layui.util.fixbar({
        top:true,css: { right: 15, bottom: 105 },showHeight:100,
        click: function (type) {if (type === 'top') $('.layui-fluid').animate({scrollTop: 0}, 200);}
    });
    $.post(geturl()+'/enums/select?token='+sessionStorage.getItem("token"), JSON.stringify({parentEnumCode:"ORDER_STATUS",orderByAscType:"enumCode"}), function (res) {
        enumsData = res.data
        showData("isSure","0","1","ORDER_STATUS_20");
    })
})
function showData(field,value,payStatus,orderStatus){
    var data = {isDel:0};
    if(!isEmpty(payStatus)) data.status = payStatus;
    if(!isEmpty(orderStatus)) data.orderStatus = orderStatus;
    if(!isEmpty(field) && !isEmpty(value)) data[field] = value;
    $.post("/cateringOrder/select",JSON.stringify(data), function (res) {
        $("#orders").html("")
        if(res.data.length == 0) $(".cartempty").removeClass("ng-hide")
        else  $(".cartempty").addClass("ng-hide")
        for(var i in res.data){
            var urlhref = '/orderdetail?orderId='+res.data[i].sysId;
            var ordersta = "display:none";
            if(res.data[i].status == 0) {
                urlhref = '/pay?orderId='+res.data[i].sysId;
                ordersta = "display:block";
            }
            $("#orders").append(
                '<li id="'+res.data[i].sysId+'" style="border-bottom: 0;background: #fff;border-radius: 10px;">' +
                '<a href="'+urlhref+'"><p>订单编号：'+res.data[i].orderNo+'<span class="status" style="line-height: 40px;font-weight:bold;">'+getOrderStatus(res.data[i].status,res.data[i].orderStatus)+'</span></p>' +
                '<p style="margin: 5px 0px;">'+res.data[i].createTime+'</p></a>' +
                '<ul id="'+res.data[i].orderNo+'" class="pdtlist" style="overflow-y: hidden;overflow-x: auto;width:auto;white-space: nowrap;width:auto;height:120px;position:inherit;">' +
                '</ul>' +
                '<div class="bottom">' +
                (res.data[i].orderStatus === 'ORDER_STATUS_20' && res.data[i].status === 1 && res.data[i].isSure === 0 ?'<a onclick="doSureOrder(\''+res.data[i].sysId+'\',1,\''+res.data[i].sendType+'\')" style="border-radius: 20px;background: #aabaf8;">确认订单</a>' : '') +
                (res.data[i].orderStatus === 'ORDER_STATUS_22' || res.data[i].orderStatus === 'ORDER_STATUS_23' ?'<a onclick="doSureOrder(\''+res.data[i].sysId+'\',2)" style="border-radius: 20px;background: #aabaf8;">确认收货</a>' : '') +
                '</div>' +
                '</li><div style="height:10px;"></div>'
            )
            var totalMoney = 0,totalNum = 0;
            for(var j in res.data[i].cartList){
                totalMoney = totalMoney+res.data[i].cartList[j].goodsNum/1*res.data[i].cartList[j].goodsPrice/1
                totalNum = res.data[i].cartList[j].goodsNum/1 + totalNum
                var marginri = "10px";
                if(j == res.data[i].cartList.length-1) marginri = "80px"
                $("#"+res.data[i].orderNo).append(
                    '<li style="display: inline-block;width: 80px;margin-right:'+marginri+';">' +
                    '<div class="l" style="width: 100%;height: 80px;">' +
                    '<img style="height: 80px;width: 80px;border-radius: 10px;" src="'+res.data[i].cartList[j].goodsImg+'" class="img-responsive" alt="..." />' +
                    '</div>' +
                    '<div class="r" style="width: 100%;padding:0;">' +
                    '<p class="t" style="padding: 0;">'+res.data[i].cartList[j].goodsName+'</p>' +
                    '</div>' +
                    '</li>'
                )
                if(j == res.data[i].cartList.length-1){
                    $("#"+res.data[i].sysId).append(
                        '<div style="opacity: 0.8;margin-top:-140px;width: 80px;height: 120px;background: #fff;right: 2%;position: absolute;">' +
                        '<div style="margin-top: 50%;text-align: center;">' +
                        '<p style="color: #0C0C0C;font-weight:bold;">￥'+parseFloat(totalMoney).toFixed(2)+'</p>' +
                        '<p>共'+totalNum+'件</p>' +
                        '</div>' +
                        '</div>'
                    )
                }
            }
        }
    })
}
function enums(s,enumCode){
    for(var key in enumsData[enumCode]) if(key === s) return enumsData[enumCode][s];
}
function getOrderStatus(pays,orders){
    if(pays == 0) return "待支付";
    else if(pays == 2) return "已取消";
    else if(pays == 3) return "已退款";
    else if(pays == 1) {
        return enums(orders,'ORDER_STATUS');
    }
}
function doSureOrder(id,orders,sendType){
    var data = {sysId:id}
    if(orders == 1){
        if(sendType == 1) data.orderStatus = 'ORDER_STATUS_03,ORDER_STATUS_04,ORDER_STATUS_21';
        else data.orderStatus = 'ORDER_STATUS_03,ORDER_STATUS_04,ORDER_STATUS_22'
        data.isSure = 1
        remark = "接受订单"
    }else if(orders == 2){
        data.orderStatus = 'ORDER_STATUS_07,ORDER_STATUS_24'
        remark = "用户收货"
    }
    layer.confirm('确认'+remark+'吗？',function(index){
        $.post("/cateringOrder/updateStatus",JSON.stringify(data), function (res) {
            layer.msg(res.msg,{icon:1,time:1500},function(){
                $(".navlist li").each(function () {
                    if($(this).attr("class") === "active"){
                        showData($(this).attr("data-field"),$(this).attr("data-value"),$(this).attr("status"),$(this).attr("order-status"))
                    }
                });
            })
        })
    })
}
$(".navlist li").each(function () {
    $(this).click(function () {
        $(".navlist li").removeClass("active");
        $(this).addClass("active");
        showData($(this).attr("data-field"),$(this).attr("data-value"),$(this).attr("status"),$(this).attr("order-status"))
    });
});
</script>
</html>

